/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Controllers;
    
import Views.Login_View;
import Views.MainMenu_MainView;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;

/**
 *
 * @author NOCTURNAL
 */
public class Login_Controller {
    private Login_View loginView;
    private MainMenu_MainView mainView;
    public Login_Controller(Login_View LoginView) {
        this.loginView = LoginView;
    }
    public void btnEnter_mouseClick(){
        if(loginView.getTxtUsername().getText().equals("seven") &&
           loginView.getTxtPassword().getText().equals("delapan")){
                JOptionPane.showMessageDialog(loginView, "Login Success!");
                try{
                new MainMenu_MainView().setVisible(true);
                loginView.dispose();
                }catch(Exception e){
                    JOptionPane.showMessageDialog(loginView, "Please check your xampp and database");
                }
                
        }else{
            JOptionPane.showMessageDialog(loginView, "Login Failed");
        }
    }
    public void btnCancel_mouseClick(){
        frmMain_windowClosing();
    }
    private void frmMain_windowClosing() {
        if(JOptionPane.showConfirmDialog(null, "Are You Sure?", "Warning",
                JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
            System.exit(0);
        }
    }
    
    public KeyAdapter EditKey_Listener = new KeyAdapter() {
        @Override
        public void keyPressed(KeyEvent Evt) {
            if(Evt.getKeyCode() == KeyEvent.VK_ENTER) {
                btnEnter_mouseClick();
            } 
        }
    };

    
    public ComponentAdapter EditComponent_Listener = new ComponentAdapter() {
        @Override
        public void componentShown(ComponentEvent Evt) {
            
        }
    };
    public WindowAdapter MainWindow_Listener = new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent Evt) {
            frmMain_windowClosing();
        }
    };
    public ActionListener EditButton_Listener = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent Evt) {
            if(Evt.getSource().equals(loginView.getBtnEnter())) {
                btnEnter_mouseClick();
            }else if(Evt.getSource().equals(loginView.getBtnCancel())){
                btnCancel_mouseClick();
            }
        }
    };
    public MouseAdapter EditButtonImg_Listener = new MouseAdapter() {
        @Override
        public void mousePressed(MouseEvent Evt) {
            if(Evt.getSource().equals(loginView.getBtnEnter())) {
                loginView.getBtnEnter().setIcon(new ImageIcon(getClass().getResource("/Images/enter2.png")));
            } else if(Evt.getSource().equals(loginView.getBtnCancel())) {
                loginView.getBtnCancel().setIcon(new ImageIcon(getClass().getResource("/Images/cancel2.png")));
            }
        }

        @Override
        public void mouseReleased(MouseEvent Evt) {
            if(Evt.getSource().equals(loginView.getBtnEnter())) {
                loginView.getBtnEnter().setIcon(new ImageIcon(getClass().getResource("/Images/enter.png")));
            } else if(Evt.getSource().equals(loginView.getBtnCancel())) {
                loginView.getBtnCancel().setIcon(new ImageIcon(getClass().getResource("/Images/cancel.png")));
            }
            
        }
    };
}
